<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
  
        喜欢苹果
        <input type="checkbox" name="apple" id="apple">
        喜欢香蕉
        <input type="checkbox" name="banana" id="banana">
        喜欢车
        <input type="checkbox" name="car" id="car" >
        <button>全选</button>
        <button>不选</button>
        <button>反选</button>

    <script>
        var btn=document.getElementsByTagName("button");
        console.log(btn);
        var inp=document.getElementsByTagName("input");
        console.log(inp)
        console.log(btn[0].innerHTML)
        for(var i=0;i<btn.length;i++)
        {
            btn[i].flag=i;
            btn[i].onclick=function(){
                if(this.innerHTML==="全选")
                {
                    for(var j=0;j<inp.length;j++)
                    {
                        inp[j].checked=true;
                        console.log(inp[j].checked);
                        
                    }
                }
                if(this.innerHTML==="不选")
                {
                    for(var j=0;j<inp.length;j++)
                    {
                        inp[j].checked=false;
                        console.log(inp[j].checked);
                        
                    }
                }
                if(this.innerHTML==="反选")
                {
                   
                    for(var j=0;j<inp.length;j++)
                    {
                        inp[j].checked=!inp[j].checked;
                        
                    }
                }
            }
        }
        
       
       
    </script>
</body>
</html>